import { ref } from 'vue';
// 初始执行一次的节流函数
export const useThrottle = () => {
  const lock = ref(false);
  return (fun: () => void, wait: number) => {
    if (lock.value) {
      console.log('节流');
      return;
    }
    lock.value = true;
    fun();
    console.log('执行函数');
    const timer = setTimeout(() => {
      lock.value = false;
      clearTimeout(timer);
    }, wait);
  };
};
